<template>
  <div class="search-history">
    <van-cell title="搜索历史">
      <div v-if="isShow">
        <span @click="$emit('allRemove')">全部删除</span> &nbsp;&nbsp;
        <span @click="isShow = false">完成</span>
      </div>
      <van-icon name="delete" @click="isShow = true" />
    </van-cell>
    <van-cell
      :title="item"
      v-for="(item, index) in SearchHistory"
      :key="index"
      @click="removeSearch(item, index)"
    >
      <van-icon name="close" v-if="isShow" />
    </van-cell>
  </div>
</template>

<script>
export default {
  name: 'SearchHistory',
  components: {},
  // props里面的数据是简单数据类型的时候不能修改,是复杂数据类型的时候,里面的属性可以修改但是不能进行赋值,需要赋值的话必须传回父组件中进行修改
  props: {
    SearchHistory: {
      type: Array,
      required: true
    }
  },
  data() {
    return {
      isShow: false
    }
  },
  computed: {},
  watch: {},
  created() {},
  mounted() {},
  methods: {
    removeSearch(item, index) {
      if (this.isShow) {
        // 如果是isShow的状态就说明是要删除
        this.SearchHistory.splice(index, 1)
      } else {
        // 反之就是搜索状态
        this.$emit('search', item)
      }
    }
  }
}
</script>

<style scoped lang="less"></style>
